/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on 2.7.2009, 13:19:16
 */
package projekt_db_dropbox;

import java.awt.Color;
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.omg.PortableInterceptor.SUCCESSFUL;

/**
 *
 * @author FReSH
 */
public class MainWindow extends javax.swing.JFrame {

    private boolean admin = false;
    private String edit_name = "";
    private boolean editing = false;
    private int zbytek;
    public String THIS_VERSION = "0.51 - ALPHA";
    private DefaultListModel polozky_seznamu = new DefaultListModel();

    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();
        unlogin();
        pripoj_DB();
        check_version();
        seznam.setSelectionMode(0);
        seznam.setModel(polozky_seznamu);
        fill_list();
        edit.setEnabled(false);
//        Database.servis(1, "heslo_admin", heslo, "", "");
    }

    public MainWindow(int i) {
        initComponents();
        unlogin();
        seznam.setSelectionMode(0);
        JOptionPane.showMessageDialog(null, "Chybí nastavení - pravděpodobně spouštíte program poprvé, proveďte prosím nastavení..\n");
        SettingsWindow nastaveni = new SettingsWindow();
        nastaveni.setVisible(true);
        nastaveni.setAlwaysOnTop(true);
        nastaveni.jButton2.setEnabled(false);
        check_version();
        seznam.setModel(polozky_seznamu);
        fill_list();
        edit.setEnabled(false);
    }

    private void check_version() {

        if (!THIS_VERSION.equals(Database.heslo("verze"))) {
            JOptionPane.showMessageDialog(null, "K dispozici je nová verze programu, kontaktujte správce nebo si stáhněte\n" +
                    "novou verzi z DropBoxu ze složky share - New_versions_sDat!\n\n" +
                    "Tato hláška zmizí s novou verzí ;) ");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jOptionPane1 = new javax.swing.JOptionPane();
        statusBar = new javax.swing.JLabel();
        add = new javax.swing.JButton();
        edit = new javax.swing.JButton();
        storno = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        seznam = new javax.swing.JList();
        refresh = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jmeno = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        slozka = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        kategorie = new javax.swing.JTextField();
        rd = new javax.swing.JCheckBox();
        rdfp1 = new javax.swing.JCheckBox();
        rdfp2 = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        th = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        plna = new javax.swing.JCheckBox();
        crack = new javax.swing.JRadioButton();
        freeware = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        popis = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        zbyva = new javax.swing.JLabel();
        statusBar1 = new javax.swing.JLabel();
        vytvoril_txt = new javax.swing.JLabel();
        datum_txt = new javax.swing.JLabel();
        vytvoril = new javax.swing.JTextField();
        datum = new javax.swing.JTextField();
        version_change = new java.awt.Button();
        button2 = new java.awt.Button();
        button3 = new java.awt.Button();
        jButton1 = new javax.swing.JButton();
        db_spoj = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        jMenuItem6 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Databaze aplikací na DropBoxu -. sDat");
        setLocationByPlatform(true);
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
            }
        });

        statusBar.setText("Vítejte v programu - sDat");

        add.setText("Uložit");
        add.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                addMouseMoved(evt);
            }
        });
        add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addActionPerformed(evt);
            }
        });

        edit.setText("Editovat");
        edit.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                editMouseMoved(evt);
            }
        });
        edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editActionPerformed(evt);
            }
        });

        storno.setText("Storno");
        storno.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                stornoMouseMoved(evt);
            }
        });
        storno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stornoActionPerformed(evt);
            }
        });

        seznam.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        seznam.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                seznamMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                seznamMouseEntered(evt);
            }
        });
        jScrollPane1.setViewportView(seznam);

        refresh.setText("Refresh");
        refresh.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                refreshMouseMoved(evt);
            }
        });
        refresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshActionPerformed(evt);
            }
        });

        jLabel1.setText("Jmeno apliakce(soubor):");

        jmeno.setNextFocusableComponent(slozka);
        jmeno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jmenoKeyPressed(evt);
            }
        });

        jLabel2.setText("Složka, ve které je:");

        slozka.setText("/");
        slozka.setNextFocusableComponent(kategorie);

        jLabel3.setText("Kategorie(použití):");

        kategorie.setText("různé");
        kategorie.setNextFocusableComponent(rd);

        rd.setText("3rd");
        rd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdActionPerformed(evt);
            }
        });

        rdfp1.setText("3rd(FP1)");
        rdfp1.setNextFocusableComponent(rdfp2);

        rdfp2.setText("3rd(FP2)");
        rdfp2.setNextFocusableComponent(th);

        jLabel4.setText("Funguje na:");

        th.setText("5th");
        th.setNextFocusableComponent(plna);

        jLabel5.setText("Plná verze:");

        plna.setText("Ano");
        plna.setNextFocusableComponent(popis);
        plna.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                plnaStateChanged(evt);
            }
        });
        plna.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plnaActionPerformed(evt);
            }
        });

        buttonGroup1.add(crack);
        crack.setSelected(true);
        crack.setText("Crack");
        crack.setEnabled(false);

        buttonGroup1.add(freeware);
        freeware.setText("FreeWare");
        freeware.setEnabled(false);

        jLabel6.setText("Popis aplikace (maximalne 700znaku):");

        popis.setColumns(20);
        popis.setLineWrap(true);
        popis.setRows(5);
        popis.setWrapStyleWord(true);
        popis.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                popisCaretPositionChanged(evt);
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        popis.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                popisPropertyChange(evt);
            }
        });
        popis.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                popisAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        popis.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                popisKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                popisKeyTyped(evt);
            }
        });
        popis.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                popisVetoableChange(evt);
            }
        });
        jScrollPane2.setViewportView(popis);

        jLabel7.setText("Zbyva znaku: ");

        zbyva.setText("700");

        statusBar1.setFont(new java.awt.Font("Aharoni", 0, 11));
        statusBar1.setForeground(new java.awt.Color(0, 255, 0));
        statusBar1.setText("mod pridavani");

        vytvoril_txt.setText("Vytvoril: ");

        datum_txt.setText("Datum přidání:");

        version_change.setLabel("verze");
        version_change.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                version_changeActionPerformed(evt);
            }
        });

        button2.setLabel("zmenit heslo");
        button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button2ActionPerformed(evt);
            }
        });

        button3.setLabel("button1");

        jButton1.setText("Vyber...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        db_spoj.setBackground(new java.awt.Color(0, 255, 0));
        db_spoj.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/odpoj.jpg"))); // NOI18N
        db_spoj.setText("DB");

        jLabel8.setText("Pripojení databáze:");

        jMenu1.setText("Soubor");

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setIcon(new javax.swing.ImageIcon("E:\\###_programování_###\\obrázyk\\delete.jpg")); // NOI18N
        jMenuItem3.setText("Smazat formulář");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setIcon(new javax.swing.ImageIcon("E:\\###_programování_###\\obrázyk\\Setings.jpg")); // NOI18N
        jMenuItem2.setText("Nastavení");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);
        jMenu1.add(jSeparator1);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/Exit.jpg"))); // NOI18N
        jMenuItem1.setText("Konec");
        jMenuItem1.setPreferredSize(new java.awt.Dimension(150, 20));
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Exit(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu4.setText("Nástroje");

        jMenu2.setText("Hledat");
        jMenu4.add(jMenu2);

        jMenuItem10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/connect.jpg"))); // NOI18N
        jMenuItem10.setText("Pripojit k databázi");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem10);

        jMenuItem11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/data_down.jpg"))); // NOI18N
        jMenuItem11.setText("Odpojit od databáze");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem11);

        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/admin.jpg"))); // NOI18N
        jMenuItem5.setText("Administratorsky ucet");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem5);

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/SQL.jpg"))); // NOI18N
        jMenuItem4.setText("SQL dotazy");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem4);

        jMenuBar1.add(jMenu4);

        jMenu3.setText("Pomoc");

        jMenuItem9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/help.jpg"))); // NOI18N
        jMenuItem9.setText("Jak s programem pracovat?");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem9);

        jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/help.jpg"))); // NOI18N
        jMenuItem8.setText("Jak vyhledávat?");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem8);

        jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/help.jpg"))); // NOI18N
        jMenuItem7.setText("Jak přidávat aplikace?");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem7);
        jMenu3.add(jSeparator2);

        jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/info.jpg"))); // NOI18N
        jMenuItem6.setText("O programu");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem6);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel1)
                                            .addComponent(jLabel2))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(slozka, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                                            .addComponent(kategorie, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(rd)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(rdfp1)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(rdfp2)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(th))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(plna)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(crack)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(freeware))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jmeno, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE))))
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(add, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(edit, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(47, 47, 47)
                                                .addComponent(vytvoril, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(datum_txt)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(datum)
                                            .addComponent(storno, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(zbyva)
                                .addGap(330, 330, 330))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(vytvoril_txt)
                                .addGap(379, 379, 379)))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(version_change, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(button3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
                            .addComponent(refresh, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(statusBar, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)
                            .addComponent(statusBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(db_spoj, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(677, 677, 677)
                        .addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jmeno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(slozka, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(kategorie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(rd)
                            .addComponent(rdfp1)
                            .addComponent(rdfp2)
                            .addComponent(th))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(plna)
                            .addComponent(crack)
                            .addComponent(freeware))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(zbyva))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(vytvoril_txt)
                            .addComponent(vytvoril, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(datum_txt)
                            .addComponent(datum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(version_change, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                    .addComponent(button3, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                    .addComponent(button2, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(add, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(edit, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(storno, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(refresh, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusBar)
                    .addComponent(db_spoj, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(3, 3, 3)
                .addComponent(statusBar1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Exit(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exit
        Database.zavri();
        System.exit(0);
    }//GEN-LAST:event_Exit

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        String heslo = new String();
        heslo = JOptionPane.showInputDialog("Tato utilita může při nevhodném použití poškodit databázi, zadej heslo admina");
        heslo = "" + heslo.hashCode();
        String heslo_right = Database.heslo("heslo_admin");
        if (heslo.equals(heslo_right)) {
            SQLWindow dotaz = new SQLWindow();
            dotaz.setVisible(true);
            dotaz.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        }
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        SettingsWindow nastaveni = new SettingsWindow();
        nastaveni.setVisible(true);
        nastaveni.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        JOptionPane.showMessageDialog(null, "Jednoduchý prográmek pro katalogizaci aplikací na společním disku.. \n" +
                "Vytvořili:\n" +
                "Majkee\n\n" +
                "Verze " + THIS_VERSION + "\n");
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        JOptionPane.showMessageDialog(null, "Nový záznam se dá přidat tak, že do políček, kam lze psát vyplníte potřebná data \n" +
                "a klinete na talčítko uložit. Ano, tak jednoduché to je.. Při editaci jste \n" +
                "informováni textem ve stavové řádce o tom, který záznam editujete, uložit ho můžete \n" +
                "opět přes tlačítko uložit, pokud ho neuložíte sami, neuloží se vůbec!! \n" +
                "Zálohování práce není implementováno - není to nutné ;)\n");
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        JOptionPane.showMessageDialog(null, "Vyhledávání v aktuální verzi nefunguje, vyčkejte nové verze... \n");
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        JOptionPane.showMessageDialog(null, "Program slouží pro zapisování a prohlížení krátkých informací o aplikacích, které sdílíme.\n" +
                "Přidávání záznamů do databáze se děje z hlavní obrazovky, stačí jen zapsat data do polí, \n" +
                "kam patří a uložit, program data zpracuje a uloží do sdílené databáze. Pokud si chcete prohlédnout\n" +
                "nějaký záznam, stačí ho v pravé části okna vybrat a dvakrát na něj kliknout - zobrazí se \n" +
                "v polích pro editaci. Zde můžete záznam pomocí tlačítka editovat upravit nebo jen prohlížet. \n" +
                "O většině operací jste informováni pomocí stavového řádku - v dolní části. \n");
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void stornoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stornoActionPerformed
        clear_all();
        editable_all();
        edit.setEnabled(false);
        mod_pridavani();
}//GEN-LAST:event_stornoActionPerformed

    private void rdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_rdActionPerformed

    private void plnaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plnaActionPerformed
    }//GEN-LAST:event_plnaActionPerformed

    private void plnaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_plnaStateChanged
        if (plna.isSelected()) {
            crack.setEnabled(true);
            freeware.setEnabled(true);
        } else {
            crack.setEnabled(false);
            freeware.setEnabled(false);
        }
    }//GEN-LAST:event_plnaStateChanged

    private void popisAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_popisAncestorAdded
    }//GEN-LAST:event_popisAncestorAdded

    private void popisPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_popisPropertyChange
    }//GEN-LAST:event_popisPropertyChange

    private void popisVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_popisVetoableChange
    }//GEN-LAST:event_popisVetoableChange

    private void jmenoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jmenoKeyPressed
}//GEN-LAST:event_jmenoKeyPressed

    private void popisKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_popisKeyTyped
    }//GEN-LAST:event_popisKeyTyped

    private void popisCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_popisCaretPositionChanged
    }//GEN-LAST:event_popisCaretPositionChanged

    private void editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editActionPerformed
        editing = true;
        editable_all();
        mod_editace();
}//GEN-LAST:event_editActionPerformed

    private void popisKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_popisKeyReleased
        zbytek = 700 - popis.getText().length();
        zbyva.setText("" + zbytek);
        if (zbytek < 0) {
            JOptionPane.showMessageDialog(null, "Počítadlo pod textem ta nebude asi jen tak, že?? - 700 znaků je maximum!!");
            String s = new String();
            String ss = popis.getText();
            for (int i = 0; i < 700; i++) {
                s = s + ss.charAt(i);
            }
            popis.setText(s);
        }
        zbytek = 700 - popis.getText().length();
        zbyva.setText("" + zbytek);
    }//GEN-LAST:event_popisKeyReleased

    private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
        if (jmeno.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Chybi jmeno!");
        } else {
            if (slozka.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "Chybi slozka!");
            } else {
                if (kategorie.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "Chybi kategorie!");
                } else {
                    if (popis.getText().isEmpty()) {
                        JOptionPane.showMessageDialog(null, "Chybi popis aplikace!");
                    } else {
                        int verze = 0;
                        int plna_num = 0;
                        if (rd.isSelected()) {
                            verze = verze + 8;
                        }
                        if (rdfp1.isSelected()) {
                            verze = verze + 4;
                        }
                        if (rdfp2.isSelected()) {
                            verze = verze + 2;
                        }
                        if (th.isSelected()) {
                            verze = verze + 1;
                        }
                        if (plna.isSelected()) {
                            plna_num = plna_num + 4;
                        }
                        if (crack.isSelected()) {
                            plna_num = plna_num + 2;
                        }
                        if (freeware.isSelected()) {
                            plna_num = plna_num + 1;
                        }
                        if (editing) {
                            if (admin) {
                                Database.update_row(edit_name, jmeno.getText(), slozka.getText(), kategorie.getText(), verze, popis.getText(), plna_num, vytvoril.getText());
                            } else {
                                Database.update_row(edit_name, jmeno.getText(), slozka.getText(), kategorie.getText(), verze, popis.getText(), plna_num, "admin");
                                clear_all();
                                mod_pridavani();
                            }
                        } else {
                            Database.pridej_polozku(jmeno.getText(), slozka.getText(), kategorie.getText(), verze, popis.getText(), plna_num, "admin");
                            clear_all();
                            fill_list();
                        }
                    }
                }
            }

        }
    }//GEN-LAST:event_addActionPerformed

    private void refreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshActionPerformed
        fill_list();
    }//GEN-LAST:event_refreshActionPerformed

    private void addMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addMouseMoved
        statusBar.setText("Uloží data do databáze a smaze formulář");
    }//GEN-LAST:event_addMouseMoved

    private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
        statusBar.setText("Vítejte v sDat - programu pro katalogizaci aplikací");
    }//GEN-LAST:event_formMouseMoved

    private void editMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_editMouseMoved
        statusBar.setText("Slouží pro editaci záznamu v databázi - vyberte záznam vpravo a klikněte na editovat...");        // TODO add your handling code here:
    }//GEN-LAST:event_editMouseMoved

    private void stornoMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stornoMouseMoved
        statusBar.setText("Smaže formulář a ukončí editaci bez uložení");
    }//GEN-LAST:event_stornoMouseMoved

    private void refreshMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_refreshMouseMoved
        statusBar.setText("Nacte seznam aplikaci z databaze..");
}//GEN-LAST:event_refreshMouseMoved

    private void seznamMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_seznamMouseClicked
        String s = (String) seznam.getSelectedValue();
        System.out.println(s);
        view(s);
        mod_pridavani();
    }//GEN-LAST:event_seznamMouseClicked

    private void seznamMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_seznamMouseEntered
    }//GEN-LAST:event_seznamMouseEntered

    private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
        Database.zavri();
        pripoj_DB();
    }//GEN-LAST:event_jMenuItem10ActionPerformed

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
        Database.zavri();
        db_spoj.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/odpoj.jpg")));
    }//GEN-LAST:event_jMenuItem11ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        clear_all();
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        if (!admin) {
            String heslo = new String();
            heslo = JOptionPane.showInputDialog("Tato utilita může při nevhodném použití poškodit databázi, zadej heslo admina");
            heslo = "" + heslo.hashCode();
            String heslo_right = Database.heslo("heslo_admin");
            if (heslo.equals(heslo_right)) {
                vytvoril.setVisible(true);
                vytvoril_txt.setVisible(true);
                datum.setVisible(true);
                datum_txt.setVisible(true);
                button2.setVisible(true);
                button3.setVisible(true);
                version_change.setVisible(true);
                admin = true;
                jMenuItem5.setText("Odhlasit admina");

            }
        } else {
            unlogin();
        }
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void version_changeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_version_changeActionPerformed
        if (admin) {
            String verze = JOptionPane.showInputDialog("Zadej číslo aktuální verze, které se má zapsat do databáze!\n");
            if (!verze.equals("this")) {
                Database.servis("UPDATE servis_majkee SET hodnota1='" + verze + "' WHERE radek='verze'");                
            } else {
                Database.servis("UPDATE servis_majkee SET hodnota1='" + THIS_VERSION + "' WHERE radek='verze'");  
            }
        }
}//GEN-LAST:event_version_changeActionPerformed

    private void button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button2ActionPerformed
        if (admin) {
            String heslo = JOptionPane.showInputDialog("Zadej nové heslo!\n");
            Database.servis("UPDATE servis_majkee SET hodnota1='" + heslo.hashCode() + "' WHERE radek='heslo_admin'");
        }
    }//GEN-LAST:event_button2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String f = majkee.load_settings();
        f = f.substring(0, f.length() - 13);
        JFileChooser file = new JFileChooser(f);
        file.setDialogTitle("Výběr souboru, který chcete popsat");
        if (file.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            String sl = file.getSelectedFile().toString();
            System.out.println(sl);
            sl = sl.replace('\\', '/');
            if (f.equals(sl.substring(0, f.length()))){
                System.out.println("Je to stejny - " + sl);
                sl = sl.substring(f.length()-1);
                System.out.println("ukrojeny kus - " + sl);
                int i = sl.length();
                char c = 'x';
                while (c != '/'){
                    i--;
                    c = sl.charAt(i);
                    System.out.println("znak - " + c + " i = "+i);
                }
                jmeno.setText(sl.substring(i+1, sl.length()));
                slozka.setText(sl.substring(0, i+1));

            } else {
                JOptionPane.showMessageDialog(this, "Bohužel nelze zatím kopírovat, soubor musíte vybrat na dropboxu..");
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainWindow().setVisible(true);
                System.out.println(" " + DO_NOTHING_ON_CLOSE);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton add;
    private java.awt.Button button2;
    private java.awt.Button button3;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JRadioButton crack;
    private javax.swing.JTextField datum;
    private javax.swing.JLabel datum_txt;
    public javax.swing.JButton db_spoj;
    private javax.swing.JButton edit;
    private javax.swing.JRadioButton freeware;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JOptionPane jOptionPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jmeno;
    private javax.swing.JTextField kategorie;
    private javax.swing.JCheckBox plna;
    private javax.swing.JTextArea popis;
    private javax.swing.JCheckBox rd;
    private javax.swing.JCheckBox rdfp1;
    private javax.swing.JCheckBox rdfp2;
    private javax.swing.JButton refresh;
    private javax.swing.JList seznam;
    private javax.swing.JTextField slozka;
    private javax.swing.JLabel statusBar;
    private javax.swing.JLabel statusBar1;
    private javax.swing.JButton storno;
    private javax.swing.JCheckBox th;
    private java.awt.Button version_change;
    private javax.swing.JTextField vytvoril;
    private javax.swing.JLabel vytvoril_txt;
    private javax.swing.JLabel zbyva;
    // End of variables declaration//GEN-END:variables

    private void pripoj_DB() {
        String cesta = majkee.load_settings();
        System.out.println("Cesta k DB - " + cesta);
        if (Database.pripoj(cesta) != 0) {
            JOptionPane.showMessageDialog(null, "Není možné připojit databázi, zkontroluj nastavení!");
            db_spoj.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/odpoj.jpg")));
        } else {
               db_spoj.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/pripoj.jpg")));
            if (!Database.test()) {
                JOptionPane.showMessageDialog(null, "Databáze neosahuje poždovaná data, zkontrolujte připojení databáze!");
                db_spoj.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projekt_db_dropbox/odpoj.jpg")));
            }
        }
    }

    private void readonly_all() {
        jmeno.setEditable(false);
        slozka.setEditable(false);
        kategorie.setEditable(false);
        rd.setEnabled(false);
        rdfp1.setEnabled(false);
        rdfp2.setEnabled(false);
        th.setEnabled(false);
        plna.setEnabled(false);
        crack.setEnabled(false);
        freeware.setEnabled(false);
        popis.setEditable(false);
        add.setEnabled(false);
    }

    private void clear_all() {
        jmeno.setText("");
        slozka.setText("/");
        kategorie.setText("různé");
        rd.setSelected(false);
        rdfp1.setSelected(false);
        rdfp2.setSelected(false);
        th.setSelected(false);
        plna.setSelected(false);
        edit.setEnabled(false);
        popis.setText("");
        mod_pridavani();

    }

    private void editable_all() {
        jmeno.setEditable(true);
        slozka.setEditable(true);
        kategorie.setEditable(true);
        rd.setEnabled(true);
        rdfp1.setEnabled(true);
        rdfp2.setEnabled(true);
        th.setEnabled(true);
        if (plna.isSelected()) {
            crack.setEnabled(true);
            freeware.setEnabled(true);
        }
        plna.setEnabled(true);
        popis.setEditable(true);
        add.setEnabled(true);
    }

    private void fill_list() {
        polozky_seznamu.removeAllElements();
        ResultSet rs = null;
        rs = Database.get_data();
        if (rs != null) {
            try {
                while (rs.next()) {
                    polozky_seznamu.addElement(rs.getString("jmeno"));
                    System.out.println("jmrno - " + rs.getString("jmeno"));
                }
            } catch (SQLException ex) {
                System.out.println("Chyba pri vypisovani do listu - " + ex);
            }
        }
    }

    private void view(String name) {
        ResultSet rs = null;
        clear_all();
        rs = Database.get_row(name);
        if (rs != null) {
            try {
                rs.next();
                jmeno.setText(rs.getString("jmeno"));
                slozka.setText(rs.getString("slozka"));
                kategorie.setText(rs.getString("kategorie"));
                popis.setText(rs.getString("popis"));
                int i = rs.getInt("verze");
                if (i > 7) {
                    i = i - 8;
                    rd.setSelected(true);
                }
                if (i > 3) {
                    i = i - 4;
                    rdfp1.setSelected(true);
                }
                if (i > 1) {
                    i = i - 2;
                    rdfp2.setSelected(true);
                }
                if (i > 0) {
                    th.setSelected(true);
                }
                i = rs.getInt("plna");
                if (i > 3) {
                    i = i - 4;
                    plna.setSelected(true);
                }
                if (i > 1) {
                    i = i - 2;
                    crack.setSelected(true);
                }
                if (i > 0) {
                    freeware.setSelected(true);
                }
                if (admin) {
                    vytvoril.setText(rs.getString("editoval"));
                    datum.setText(rs.getString("datum"));
                }


            } catch (SQLException ex) {
                System.out.println("Chyba pri vypisovani - " + ex);
            }
            editing = false;
            edit_name = name;
            edit.setEnabled(true);
            readonly_all();
        }
    }

    private void mod_pridavani() {
        statusBar1.setText("mod pridavani");
        statusBar1.setForeground(new java.awt.Color(0, 255, 0));
    }

    private void mod_editace() {
        statusBar1.setText("mod editace");
        statusBar1.setForeground(new java.awt.Color(255, 0, 0));
    }

    private void unlogin() {
        vytvoril.setVisible(false);
        vytvoril_txt.setVisible(false);
        datum.setVisible(false);
        datum_txt.setVisible(false);
        button2.setVisible(false);
        button3.setVisible(false);
        version_change.setVisible(false);
        admin = false;
        jMenuItem5.setText("Administratorsky ucet");
    }
}
